<?php
//易联云oauth2.0开放应用服务模式sdk
include('YlyService.class.php');
$model = new ylyApi();
/**
 * 获取code
 * 获取跳转$url关联易联云,code返回到redirect_uri对应的应用后端程序中然后get获取;
 * 返回样式:
    redirect_uri?response_type=code&code=xxxx&state=xxxx
 */
$data = [
    'client_id'=>'',
    'response_type'=>'code',
    'redirect_uri'=>'',
    'state'=>'yly',
];
$data = http_build_query($data);
$url = 'https://open-api.10ss.net/oauth/authorize?'.$data;
header('location:'.$url);


/**
 * 获取access_token并添加打印机.
 * 返回样式:
    {"error":"0","error_description":"success","body":{"access_token":"xxxx","refresh_token":"xxxx","expires_in":2592000,"scope":"all"}}
 */
$data = [
    'client_id'=>'',
    'grant_type'=>'authorization_code',
    'code'=>'',
    'scope'=>'all',
    'issign' => true,      //是否需要签名sign
    'uuid' => true,        //是否需要uuid
    'timestamp'=>time(),
];
$msg = $model->ServiceInlet($data,'Token');


/**
 * 极速授权模式获取token并绑定打印机
 * 返回样式:
    {"error":"0","error_description":"success","body":{"access_token":"xxxx","refresh_token":"xxxx","expires_in":2592000,"scope":"all"}}
 */
$data = [
    'client_id'=>'',
    'machine_code'=>'',
    'qr_key'=>'',
    'scope'=>'all',
    'issign' => true,      //是否需要签名sign
    'uuid' => true,        //是否需要uuid
    'timestamp'=>time(),
];
$msg = $model->ServiceInlet($data,'scancodemodel');


/**
 * 刷新access_token
 * 返回样式:
    {"error":"0","error_description":"success","body":{"access_token":"xxxx","refresh_token":"xxxx","expires_in":2592000,"scope":"all"}}
 */
$data = [
    'client_id'=>'',
    'refresh_token'=>'',
    'grant_type'=>'refresh_token',
    'scope'=>'all',
    'issign' => true,      //是否需要签名sign
    'uuid' => true,        //是否需要uuid
    'timestamp'=>time(),
];
$msg = $model->ServiceInlet($data,'Token');


/**
 * 删除终端授权
 * 返回样式
    {"error":"0","error_description":"success"}
 */
$data = [
    'client_id'=>'',
    'access_token'=>'',
    'machine_code'=>'',
    'issign' => true,      //是否需要签名sign
    'uuid' => true,        //是否需要uuid
    'timestamp'=>time(),
];
$msg = $model->ServiceInlet($data,'delPrint');


/**
 * 打印接口
 * 返回样式:
    {"error":"0","error_description":"success","body":{"id":"订单号","origin_id":""}}
 */
$data = [
    'client_id'=>'',
    'access_token'=>'',
    'machine_code'=>'',
    'content'=>'',
    'origin_id'=>'',
    'issign' => true,      //是否需要签名sign
    'uuid' => true,        //是否需要uuid
    'timestamp'=>time(),
];
$msg = $model->ServiceInlet($data,'Print');


/**
 * 应用菜单接口
 * 返回样式:
    {"error":"0","error_description":"success"}
 */
$data = [
    'client_id'=>'',
    'access_token'=>'',
    'machine_code'=>'',
    'content'=>json_encode(['name','url']),
    'issign' => true,      //是否需要签名sign
    'uuid' => true,        //是否需要uuid
    'timestamp'=>time(),
];
$msg = $model->ServiceInlet($data,'addMenu');


/**
 * 关机重启接口
 * 返回样式:
    {"error":"0","error_description":"success"}
 */
$data = [
    'client_id'=>'',
    'access_token'=>'',
    'machine_code'=>'',
    'response_type'=>'', //重启:restart,关闭:shutdown
    'issign' => true,      //是否需要签名sign
    'uuid' => true,        //是否需要uuid
    'timestamp'=>time(),
];
$msg = $model->ServiceInlet($data,'shutdownRestart');



/**
 * 声音调节接口
 * 返回样式:
    {"error":"0","error_description":"success"}
 */
$data = [
    'client_id'=>'',
    'access_token'=>'',
    'machine_code'=>'',
    'response_type'=>'', //蜂鸣器:buzzer,喇叭:horn
    'voice'=>'',         //[1,2,3] 3种音量设置
    'issign' => true,      //是否需要签名sign
    'uuid' => true,        //是否需要uuid
    'timestamp'=>time(),
];
$msg = $model->ServiceInlet($data,'setsound');


/**
 * 获取机型打印宽度接口
 * 返回样式:
    {"error":"0","error_description":"success","body":{"version":"机型","print_width":"??mm"}}
 */
$data = [
    'client_id'=>'',
    'access_token'=>'',
    'machine_code'=>'',
    'issign' => true,      //是否需要签名sign
    'uuid' => true,        //是否需要uuid
    'timestamp'=>time(),
];
$msg = $model->ServiceInlet($data,'printinfo');


/**
 * 获取机型软硬件版本接口
 * 返回样式:
    {"error":"0","error_description":"success","body":{"hardware":"硬件版本","software":"软件版本"}}
 */
$data = [
    'client_id'=>'',
    'access_token'=>'',
    'machine_code'=>'',
    'issign' => true,      //是否需要签名sign
    'uuid' => true,        //是否需要uuid
    'timestamp'=>time(),
];
$msg = $model->ServiceInlet($data,'getversion');


/**
 * 取消所有未打印订单接口
 * 返回样式:
    {"error":"0","error_description":"success"}
 */
$data = [
    'client_id'=>'',
    'access_token'=>'',
    'machine_code'=>'',
    'issign' => true,      //是否需要签名sign
    'uuid' => true,        //是否需要uuid
    'timestamp'=>time(),
];
$msg = $model->ServiceInlet($data,'cancelall');


/**
 * 取消单条未打印订单接口
 * 返回样式:
    {"error":"0","error_description":"success"}
 */
$data = [
    'client_id'=>'',
    'access_token'=>'',
    'machine_code'=>'',
    'order_id'=>'',
    'issign' => true,      //是否需要签名sign
    'uuid' => true,        //是否需要uuid
    'timestamp'=>time(),
];
$msg = $model->ServiceInlet($data,'cancelone');


/**
 * 设置logo接口
 * 返回样式:
    {"error":"0","error_description":"success"}
 */
$data = [
    'client_id'=>'',
    'access_token'=>'',
    'machine_code'=>'',
    'img_url'=>'',       //图片地址,图片宽度最大为350px,文件大小不能超过40Kb
    'issign' => true,      //是否需要签名sign
    'uuid' => true,        //是否需要uuid
    'timestamp'=>time(),
];
$msg = $model->ServiceInlet($data,'setlogo');



/**
 * 取消logo接口
 * 返回样式:
    {"error":"0","error_description":"success"}
 */
$data = [
    'client_id'=>'',
    'access_token'=>'',
    'machine_code'=>'',
    'issign' => true,      //是否需要签名sign
    'uuid' => true,        //是否需要uuid
    'timestamp'=>time(),
];
$msg = $model->ServiceInlet($data,'dellogo');


/**
 * 订单确认接口
 * 返回样式:
    {"error":"0","error_description":"success","body":"open"}
    {"error":"0","error_description":"success","body":"close"}
 */
$data = [
    'client_id'=>'',
    'access_token'=>'',
    'machine_code'=>'',
    'response_type' => '', //开启open 关闭close
    'issign' => true,      //是否需要签名sign
    'uuid' => true,        //是否需要uuid
    'timestamp'=>time(),
];
$msg = $model->ServiceInlet($data,'getorder');


/**
 * 订单确认接口
 * 返回样式:
{"error":"0","error_description":"success","body":"open"}
{"error":"0","error_description":"success","body":"close"}
 */
$data = [
    'client_id'=>'',
    'access_token'=>'',
    'machine_code'=>'',
    'response_type' => '', //开启open 关闭close
    'issign' => true,      //是否需要签名sign
    'uuid' => true,        //是否需要uuid
    'timestamp'=>time(),
];
$msg = $model->ServiceInlet($data,'getorder');